package com.centaline.androidsalesblog.rx.database;

import com.centaline.androidsalesblog.constants.AppConstant;
import com.centaline.androidsalesblog.model.databaseobject.SearchDataDo;

import org.litepal.crud.DataSupport;

import java.util.ArrayList;

import rx.Observable;
import rx.Subscriber;

/**
 * SearchData
 * Created by guilin on 16/1/25.
 */
final class SearchDataOnSubscribe implements Observable.OnSubscribe<ArrayList<SearchDataDo>> {

    private final String name;

    public SearchDataOnSubscribe(String name) {
        this.name = name;
    }

    @Override
    public void call(Subscriber<? super ArrayList<SearchDataDo>> subscriber) {
        final ArrayList<SearchDataDo> list = new ArrayList<>();
        list.addAll(DataSupport.where("name = ? and cityCode = ?", name, AppConstant.CityCode).find(SearchDataDo.class));
        if (!subscriber.isUnsubscribed()) {
            subscriber.onNext(list);
        }
        subscriber.onCompleted();
    }
}
